package priv.pront.code.national.acwing.graph;

import java.util.Scanner;
import java.util.Arrays;
import java.util.Queue;
import java.util.LinkedList;

public class A852_SPFA判断负环 {

    static int n, m, idx;
    static boolean[] st;
    static int[] dis, ne, cnt, e, h, w;
    static Queue<Integer> queue = new LinkedList<>();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        ne = new int[m + 10];
        cnt = new int[m + 10];
        e = new int[m + 10];
        h = new int[n + 10];
        st = new boolean[m + 10];
        w = new int[m + 10];
        dis = new int[m + 10];
        Arrays.fill(h, -1);
        for (int i = 1; i <= m; i++) add(scanner.nextInt(), scanner.nextInt(), scanner.nextInt());
        System.out.println(spfa() ? "Yes" : "No");
    }

    private static boolean spfa() {

        for (int i = 1; i <= n; i++) {
            st[i] = true;
            queue.add(i);
        }
        while (!queue.isEmpty()) {
            int t = queue.poll();
            st[t] = false;
            for (int i = h[t]; i != -1; i = ne[i]) {
                int j = e[i];
                if (dis[j] > dis[t] + w[i]) {
                    dis[j] = dis[t] + w[i];
                    cnt[j] = cnt[t] + 1;
                    if (cnt[j] >= n) return true;
                    if (!st[j]) {
                        queue.add(j);
                        st[j] = true;
                    }
                }
            }
        }
        return false;

    }

    private static void add(int a, int b, int weight) {
        e[idx] = b;
        ne[idx] = h[a];
        w[idx] = weight;
        h[a] = idx++;
    }
}
